package com.example.sr.schedulerTask;



import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

public class Tests {


    static class MyReenrantLock implements Runnable {
        //向上转型
        private Lock lock = new ReentrantLock();

        public void run() {
            //上锁
            lock.lock();
            for (int i = 0; i < 5; i++) {
                System.out.println("当前线程名： " + Thread.currentThread().getName() + " ,i = " + i);
            }
            //释放锁
            lock.unlock();
        }
    }
}
        class MyLock {
            public static void main(String[] args) {
                 Lock lock = new ReentrantLock();
                lock.lock();
                Tests.MyReenrantLock myReenrantLock = new Tests.MyReenrantLock();
                Thread thread1 = new Thread(myReenrantLock);
                thread1.setName("一号");
                Thread thread2 = new Thread(myReenrantLock);
                thread2.setName("二号");
                thread1.start();
                thread2.start();
                if (thread1.getName().equals("一号")){
                    System.out.println("一号获得了锁");
                }else{

                }


            }
        }






